﻿using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace RapidDownloader.Model.Services.HotFile
{
    public sealed partial class HotFileDownloadProvider : IDownloadProvider
    {
        #region Public Methods

        public void CheckFiles(IEnumerable<DownloadFile> files)
        {
            // TODO: Check Files
        }

        public IEnumerable<DownloadFile> GetFiles(string text)
        {
            return Regex.Matches(text, "https?://(?:www.)?hotfile.com/dl/(\\d+/[a-z0-9]+)/([^ \r\n\"]+)").Cast<Match>().Select(m => new HotFileFile(NoHtml(m.Groups[2].Value)));
        }

        #endregion

        #region Class Methods

        private static string NoHtml(string value)
        {
            return value.EndsWith(".html") ? value.Substring(0, value.Length - 5) : value;
        }

        #endregion
    }
}